﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;
using System.Web.Security;

namespace DataAccess
{
    public class PostDataAccess
    {
        public void CreatePost(Post post)
        {
            Database db = DatabaseFactory.CreateDatabase();

            string sql = "insert into Post(UserId,InfoType,ServiceName,CategoryId,Title,Expire," +
                        "Details,IsCommercial) " +//,Image1,Image2,Image3
                        "values(@UserId,@InfoType,@ServiceName,@CategoryId" +
                        ",@Title,@Expire,@Details,@IsCommercial)";//,@Image1,@Image2,@Image3

            DbCommand command = db.GetSqlStringCommand(sql);

            db.AddInParameter(command, "@UserId", DbType.String, post.UserId);
            db.AddInParameter(command, "@InfoType", DbType.String, post.InfoType);
            db.AddInParameter(command, "@ServiceName", DbType.String, post.ServiceName);
            db.AddInParameter(command, "@CategoryId", DbType.String, post.CategoryId);
            db.AddInParameter(command, "@Title", DbType.String, post.Title);
            db.AddInParameter(command, "@Expire", DbType.String, post.Expire);
            db.AddInParameter(command, "@Details", DbType.String, post.Details);
            //db.AddInParameter(command, "@Image1", DbType.String, post.Image1);
            //db.AddInParameter(command, "@Image2", DbType.String, post.Image2);
            //db.AddInParameter(command, "@Image3", DbType.String, post.Image3);
            db.AddInParameter(command, "@IsCommercial", DbType.Boolean, post.IsCommercial);

            db.ExecuteNonQuery(command);

        }

    }
}
